package com.itheima.advantagesup.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.advantagesup.common.PageBean;
import com.itheima.advantagesup.dto.UserPageDTO;
import com.itheima.advantagesup.entity.YddUser;
import com.itheima.advantagesup.mapper.YddUserMapper;
import com.itheima.advantagesup.service.YddUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName: YddUserServiceImpl
 * @description:
 * @author: zhao qianfeng
 * @date: 2023年07月31日
 * @version: 1.0
 */
@Service
public class YddUserServiceImpl implements YddUserService {
    @Autowired
    private YddUserMapper yddUserMapper;
    @Override
    public PageBean pageList(UserPageDTO userPageDTO) {
        PageHelper.startPage(Integer.valueOf(userPageDTO.getPage()),Integer.valueOf(userPageDTO.getLimit()));
        YddUser yddUser = new YddUser();
        BeanUtils.copyProperties(userPageDTO,yddUser);

        Page <YddUser> page = yddUserMapper.selectList(yddUser);
        Integer count = yddUserMapper.selectCount();
        PageBean pageBean = new PageBean(count,(int)page.getTotal(),Integer.valueOf(userPageDTO.getLimit()),1,page.getResult());
        return pageBean;
    }
}
